#!/usr/bin/perl -w

# ampm
# File ID: 18c94c16-5d37-11df-b31a-90e6ba3022ac
# Konverterer fra helsikes am/pm til 24-timers klokke

use strict;

while (<>) {

	# 12:00am til 12:59am
	#   Trekk fra 12 timer
	#   12:59am = 00:59
	s/(12)(:[0-5][0-9]:[0-5][0-9]) ?am/sprintf("%02u%s", $1-12, $2)/gei;
	s/(12)(:[0-5][0-9]) ?am/sprintf("%02u%s", $1-12, $2)/gei;

	# 01:00pm til 11:59pm
	#   Legg til 12 timer
	#   10:59pm = 22:59
	s/0?([1-9]|10|11)(:[0-5][0-9]:[0-5][0-9]) ?pm/sprintf("%02u%s", $1+12, $2)/gei;
	s/0?([1-9]|10|11)(:[0-5][0-9]) ?pm/sprintf("%02u%s", $1+12, $2)/gei;

	# Resten av driten stripper vi bort am/pm fra
	s/0?([1-9]|10|11|12)(:[0-5][0-9]:[0-5][0-9]) ?(am|pm)/$1$2/gi;
	s/0?([1-9]|10|11|12)(:[0-5][0-9]) ?(am|pm)/$1$2/gi;

	print;
}
